package com.bbz.core.lambda.java8.Chapter_8_Refactoring;

import java.util.Comparator;

import static java.util.Comparator.comparing;

public class Point {
    private final int x;
    private final int y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    /**
     * comparing 按照x比较，x相等情况下 按照thenComparing(y)比较
     */
    public final static Comparator<Point> compareByXAndThenY= comparing(Point::getX).thenComparing(Point::getY);



    public static  void main(String args[]){
        Point p1 = new Point(5, 20);
        Point p2 = new Point(10, 20);
        int result = Point.compareByXAndThenY.compare(p1 , p2);
        System.out.println(result);
    }
}
